package com.example.demo.Service;

import com.example.demo.Mappers.RegistMapper;
import com.example.demo.Mappers.ZYAddDepositMapper;
import com.example.demo.beans.PayDetailBean;
import com.example.demo.beans.ZYAddDepositRequest;
import com.example.demo.beans.ZYAddDepositResponse;
import com.example.demo.beans.ZyjfcxBean;
import com.example.demo.utils.AppConfigUtils;
import com.example.demo.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by Administrator on 2018-06-29.
 */
@Service("ZYAddDepositService")
public class ZYAddDepositService {
@Autowired
private ZYAddDepositMapper mapper;
@Autowired
private RegistMapper rmapper;
@Transactional(readOnly = true)
    public ZYAddDepositResponse ZyAddFee(ZYAddDepositRequest r)
    { String czybm= AppConfigUtils.getGhybm();
    String zflxbm="01";
        ZyjfcxBean zyjfcxBean=mapper.getzyjfinfo(r.getZyno(),r.getCardNo());
        if(zyjfcxBean==null)
        { ZYAddDepositResponse res=new ZYAddDepositResponse();
        res.setResultCode("0");
        res.setResultMsg("系统根据您提供的医疗卡号和住院号没有查询到您的信息，请到收费窗口办理!");
        return res;
        }
        double payamt= Double.parseDouble((r.getPayAmt()));
        double yjjhj=(payamt+Double.valueOf(zyjfcxBean.getYlkzhje()));
      mapper.Zyaddinsert(zyjfcxBean.getYlklxbm(),zyjfcxBean.getYlkh(),zflxbm,czybm,zyjfcxBean.getRyks(),zyjfcxBean.getZyh(), DateUtils.Getdnowdatexx(),r.getPayAmt());
      mapper.Zyupdate(yjjhj,zyjfcxBean.getYlkh(),zyjfcxBean.getYlklxbm(),zyjfcxBean.getZyh());
        String jsjlid=mapper.getyjjlid();
        setpaybean(r,zyjfcxBean,jsjlid);
        ZYAddDepositResponse response =new ZYAddDepositResponse();
        response.setResultCode("0");
        response.setResultMsg("交易成功");
        response.setHosTranNo(jsjlid);
        response.setOpDateTime(DateUtils.Getdnowdatexx());
        return response;
    }


    private void setpaybean(ZYAddDepositRequest request,ZyjfcxBean bean,String jsxh)
    {
        PayDetailBean d =new PayDetailBean();
        d.setPayTag(request.getPayTag());
        d.setCodeTermidNo(request.getCodeTermidNo());
       d.setPayTranDate(request.getPayTranDate());
        d.setCardNo(bean.getYlkh());
        d.setCardType(bean.getYlklxbm());
        d.setPatientID(bean.getBrid());
        d.setName(bean.getBrxm());
        d.setSex(bean.getBrxb());
        d.setBirthday(bean.getCsrq());
        d.setIDCardNo(bean.getSfzh());
        d.setMobile(bean.getSj());
        d.setAddress(bean.getJtzz());
        d.setPayTag(request.getPayTag());
        d.setPayAmt(request.getPayAmt());
        d.setBankCardNo(request.getBankCardNo());
        d.setBankTranNo(request.getBankTranNo());
        d.setBankPNo(request.getBankPNo());
        d.setBankReferNo(request.getBankReferNo());
        d.setBankTermid(request.getBankTermid());
        d.setCodeBuyerAccount(request.getCodeBuyerAccount());
        d.setCodeTradeOrderNo(request.getCodeTradeOrderNo());
        d.setCodeTermidNo(request.getCodeTermidNo());
        d.setPayTranDate(request.getPayTranDate());
        d.setPayTranTime(request.getPayTranTime());
        d.setAutoTranNo(request.getAutoTranNo());
        d.setUserId(request.getUserID());
        d.setBzms("住院预交金");
        d.setJsxh(jsxh);
        d.setReqtype(request.getReqtype());
        rmapper.saverePaybean(d);

    }
}
